// Copyright (c) 2010 Manuel Peinado Gallego <manuel.peinado@gmail.com>
// Distributed under the MIT license


#include "stdafx.h"
#include "WorldBuilder.h"
#include "View3d.h"
#include "Drawable.h"


WorldView::WorldView()
: m_world(NULL)
{
}

WorldView::~WorldView()
{
    // TODO use RAII!!
    if(m_world)
    {
        m_world->getSelectionManager().removeSelectionChangeListener(this);
        m_world->getNodeManager().removeNodeListener(this);
        m_world->getMaterialManager().removeMaterialListener(this);
    }
}

// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  

World* WorldView::getWorld()
{
    return m_world;
}

void WorldView::setWorld(World* world)
{
    m_world = world;
    
    if(m_world)
    {
        // Register this view as a selection and block listener
        m_world->getSelectionManager().addSelectionChangeListener(this);
        m_world->getNodeManager().addNodeListener(this);
        m_world->getMaterialManager().addMaterialListener(this);
    }

    onWorldChanged(world);
}
